new Vue({
  el: "#app",
  data() {
    return {
      UserID: decodeURI($.cookie("use")),
      basePath: "https://www.kdddy.cn/Image/",
      // url: "http://192.168.10.73:8087/1736580641130.png",
      form: {
        SQLSerialNumber: "P_business_brand",
        limit: 10, //页数
        page: 1, //每页数据条数
        Brand_Name: "",
        Condition: "",
        ExtensionCondition: "",
      },
      total: 0,
      tableData: [], //表格数据
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // qiyebh() {
    //   let Arg_UserID = sessionStorage.getItem("User_Number");
    //   // console.log(this.UserID);
    //   const _this = this;
    //   $.ajax({
    //     headers: {
    //       AccessToken: $.cookie("token"), //会将数据转换为query string
    //     },
    //     // headers: requestHeaders(),
    //     url: "https://service.kdddy.cn/donghuiForRequest/selectByData/selectEnterpriseID",
    //     type: "get",
    //     data: {
    //       Data: Arg_UserID,
    //     },
    //     success: function (Result) {
    //       console.log(Result);

    //       // console.log(Result.Data[0].Enterprise_Info_SerialNumber);
    //       _this.getList(); //前端分页
    //     },
    //     complete: function (XMLHttpRequest) {
    //       requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
    //     },
    //     dataType: "json",
    //   });
    // },
    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form);
    },
    Add() {
      window.location.href = "./add.html";
    },
    handleSizeChange(val) {
      console.log(val);
      this.form.page = 1;
      this.form.limit = val;
      // this.getList(this.form);
    },
    handleCurrentChange(val) {
      console.log("handleCurrentChange", val);
      this.form.page = val;
      // this.getList(this.form);
    },
    getList() {
      // let a = $.cookie("enterprise");
      let Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      //换页方法
      const that = this;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "business_brand",
          Condition:
            "Row_Status='0' And Enterprise_Number='" +
            Enterprise_Info_SerialNumber +
            "'",
        },
        success: function (Result) {
          console.log(Result);

          that.tableData = Result;
          //   that.total = Result.TotalRows;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    handleDelete(index, row) {
      const _this = this;
      console.log(index, row);
      row.Row_Status = "1";
      console.log(row);
      delete row.Operation_Datetime;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_business_brand = new Object();
      lJSONObject_business_brand.business_brand = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Modify = lJSONObject_business_brand;
      console.log(lJSONObject_DataSet);

      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            _this.tableData.splice(index, 1);
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    Edit(row) {
      console.log(row.Brand_SerialNumber);
      console.log(row);
      let Brand_SerialNumber = row.Brand_SerialNumber;
      sessionStorage.setItem("Brand_SerialNumber", Brand_SerialNumber);
      window.location.href =
        "./edit.html?Brand_SerialNumber=" + Brand_SerialNumber;
    },
    Remove(row) {
      const _this = this;

      row.Row_Status = "1";
      delete row.Operation_Datetime;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_business_article_info = new Object();
      lJSONObject_business_article_info.business_article_info = lArray; //换表
      let lJSONObject_DataSet = new Object();
      lJSONObject_DataSet.Modify = lJSONObject_business_article_info;
      console.log(lJSONObject_DataSet);

      // return;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        // headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            _this.tableData.splice(index, 1);
            // _this.getList();
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
      return;
      this.$confirm("警告！此操作将删除该品牌, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row.Row_Status = "1";
          $.ajax({
            headers: requestHeaders(),
            url: `${BASE_URL2}/generalBusiness/generalSave`,
            type: "POST",
            data: {
              Data: JSON.stringify({
                Modify: { business_brand: [row] },
                Add: {
                  base_operation_log: [
                    generateLog(
                      "删除品牌数据(" + row.Brand_Name + ")",
                      "平台端操作",
                      "business_brand",
                      JSON.stringify({ Modify: { business_brand: [row] } })
                    ),
                  ], //日志
                },
              }),
            },
            success: function (res) {
              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: "删除成功!",
                });
                that.getList(that.form);
              } else {
                that.$message.error("删除失败，请稍后再试");
              }
            },
            complete: function (XMLHttpRequest) {
              that.loading = false;
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });
        })
        .catch(() => {});
    },
  },
});
